package com.batchaps.classes;

import java.util.Random;

import javax.microedition.lcdui.Graphics;

import com.batchaps.global.GameEngine;

public class Enemy1 {
	private int iWidth, iHeight;
	private Sprite2D Enemy;
	private int health, havePower, isDeath;

	public Enemy1(String strEnemy, int nEnemy, String strType, int width,
			int height) {
		iWidth = width;
		iHeight = height;
		health = 2;
		isDeath = 0;

		Enemy = new Sprite2D(strEnemy, nEnemy, strType, width, height,
				GameEngine.EnemySize, GameEngine.EnemySize, 0, 0);
	}

	public void Draw(Graphics g) {
		Enemy.Draw(g);
	}

	public void setPosition(float x, float y) {
		Enemy.set_visible(true);
		Enemy.set_posX(x);
		Enemy.set_posY(y);
	}

	public Sprite2D getEnemy() {
		return Enemy;
	}

	// di chuyển xuống từ 2 phía
	public void moveEnemyDownFrom2Sides(int index, int scrY) {
		if (index % 2 == 0) {
			Enemy.Move(5, 10);
		} else {
			Enemy.Move(-5, 10);
		}
		if (Enemy.getY() - Enemy.get_height() / 2 > 0 + iHeight) {
			Enemy.set_visible(false);
		}
	}

	// di chuyển ngang từ 2 phía
	public void moveEnemyHorizontalFrom2Sides(int index, int scrY) {
		if (index % 2 == 0) {
			Enemy.Move(15, 10);
			// Enemy.NextFrame();
		} else {
			Enemy.Move(-15, 10);
			// Enemy.NextFrame();
		}
		if (Enemy.getY() - Enemy.get_height() / 2 > 0 + iHeight) {
			Enemy.set_visible(false);
		}
	}

	// di chuyển chéo xuống sang phải
	public void moveDiagonalDownToRight(int scrY) {
		Enemy.Move(5, 10);
		if (Enemy.getY() - Enemy.get_height() / 2 > 0 + iHeight) {
			Enemy.set_visible(false);
		}
	}

	// di chuyển chéo xuống sang trái
	public void moveDiagonalDownToLeft(int srcY) {
		Enemy.Move(-5, 10);
		// Enemy.NextFrame();
		if (Enemy.getY() - Enemy.get_height() / 2 > 0 + iHeight) {
			Enemy.set_visible(false);
		}
	}

	public int getHealth() {
		return health;
	}

	public void setHealth(int health) {
		this.health = health;
	}

	public void setCondition() {
		int iX = (int) Enemy.getX();
		int iY = (int) Enemy.getY();
		if (health <= 0) {
			Random ran = new Random();
			havePower = ran.nextInt(2);
			Enemy.set_visible(false);
			isDeath = 2;
			health = 2;
//			death.setPosition(iX, iY);
//			death.set_visible(true);
//			if (havePower == 1) {
//				power.setPosition(iX, iY);
//				power.set_visible(true);
//			}
			// sound.enemyDeathSound();
		}
		if (isDeath >= 0) {
			//death.NextFrame();
			isDeath--;
		} else {
			//death.set_visible(false);
		}
	}

	public int checkFire(Sprite2D sprite, int health) {
		if (Enemy.CollidesWith(sprite)) {
			Enemy.set_visible(false);
			health--;
		}
		return health;
	}

	public int checkPower(Sprite2D sprite, int pow, int scrY) {
//		if (power.CollidesWith(sprite)) {
//			power.set_visible(false);
//			pow++;
//		}
//		if (power.getY() > scrY + iHeight) {
//			power.set_visible(false);
//		}
		return pow;
	}

	public int getPosition() {
		return (int) Enemy.getY();
	}

	public void refreshEnemy() {
		Enemy.set_visible(false);
	}
}
